package com.guge.sports.toolPackage.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.guge.sports.annotation.IgnoreSwaggerParameter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.Data;
import lombok.experimental.Accessors;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 封装分页结果和分页参数
 *
 * @param <T>
 */

@Data
@Accessors(chain = true)
@ApiModel("分页封装类")
public class MyPager<T> {

    @ApiModelProperty(value = "当前页,默认为1")
    private int currentPage = 1; //当前页

    @ApiModelProperty(hidden = true)
    private int totalCount; //总记录数

    @ApiModelProperty(hidden = true)
    private int totalPage;  //总页数

    @ApiModelProperty(value = "每页条数,默认为6",position = 1)
    private int pageCount = 6;  //每页条数
    /*@ApiModelProperty(value = "每页条数")
    private int showNum;  //页面显示九个分页,应为奇数*/
    //private T entity

    @ApiModelProperty(hidden = true)
    @IgnoreSwaggerParameter
    private List<T> list;  //查询结果

    @ApiModelProperty(hidden = true)
    private int startIndex;

   /* public T getEntity() {
        return entity;
    }

    public void setEntity(T entity) {
        this.entity = entity;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getStartPage() {
        getTotalPage();
        if (totalPage <= showNum) {
            return 1;
        } else if (currentPage <= showNum / 2) {
            return 1;
        } else if (currentPage >= totalPage - showNum / 2) {
            return totalPage - showNum + 1;
        } else {
            return currentPage - showNum / 2;
        }

    }

    public int getEndPage() {
        getTotalPage();
        if (totalPage <= showNum) {
            return totalPage;
        } else if (currentPage <= showNum / 2) {
            return showNum;
        } else if (currentPage >= totalPage - showNum / 2) {
            return totalPage;
        } else {
            return currentPage + showNum / 2;
        }
    }


    public int getPageCount() {
        return pageCount;
    }

    public int getShowNum() {
        return showNum;
    }

    public void setShowNum(int showNum) {
        this.showNum = showNum;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotolCount(int totolCount) {
        this.totalCount = totolCount;
    }
*/

    public MyPager<T> calcuStartIndex() {
        startIndex = pageCount * (currentPage - 1);
        return this;
    }

    public MyPager<T> calcuTotalPage() {
        if (totalCount > 0 && pageCount > 0) {
            //计算出总页数
            totalPage = (int) Math.ceil(totalCount * 1f / pageCount);
            //this.totalPage= totalPage;
        }
        return this;
    }

   /* public void setTotalPage(int totolPage) {
        this.totalPage = totolPage;
    }

    public int getPageCount(int pageCount) {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getIndexStart() {
        return pageCount * (currentPage - 1) + 1;
    }

    public int getIndexEnd() {
        return pageCount * currentPage;
    }*/

    public void warp2MyPager(IPage iPage) {
        totalCount = (int) iPage.getTotal();
        totalPage = (int) iPage.getPages();
        list = iPage.getRecords();
    }


}
